package practice1_100;

import java.util.*;

public class Practice783 {
    public int minDiffInBST(TreeNode root) {
        List<Integer> list=new ArrayList<>();
        midvisit(root ,list);
        int res=Integer.MAX_VALUE;
        for (int i = 0; i < list.size()-1; i++) {
             res=res<list.get(i+1)- list.get(i)?res:list.get(i+1)- list.get(i);
        }
        return res;
    }

    private void midvisit(TreeNode root,List<Integer> list) {
        if(root.left!=null) midvisit(root.left, list);
        list.add(root.val);
        if(root.right!=null) midvisit(root.right,list);
    }


        public static void main(String[] args) {
    //        [90,69,null,49,89,null,52]
           int a= new Practice783().minDiffInBST(new TreeNode(90,new TreeNode(69,new TreeNode(49,null,new TreeNode(52)),new TreeNode(89)),null));
            System.out.println(a);

        }
}
